﻿using Janus.Mes.DTO;
using Janus.Mes.Services;
using Janus.Mes.Services.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Janus.Cores.Linq;
using Janus.BaseEntitys;
using Janus.Cores;
using System.Diagnostics;
using Janus.ExpressionSerialization;
using System.Collections;
using Janus.Cores.Tools;
using Janus.Cores.Extension;

namespace Tests.Janus.Mes.ServicesConsole
{
 public   class AssetsTest
    {
        IAssets services = ServiceFactory.Create<IAssets>();
        public AssetsTest()
        { BatchUpdate(); }

        private List<AssetsDTO> BatchInsert(int count = 50000)
        {
            var models = new List<AssetsDTO>();
            for (int i = 1; i <= count; i++)
            {
                var model = new AssetsDTO();
                model.AssetsCode = i.ToString() ;
                model.AssetsName = i + "Add" + DateTime.Now.ToString("yyyyMMddHH");
                model.Id = model.NewGuid2();
                model.SN = i.ToString();
                model.UseDate = DateTime.Now.AddDays(i);
                model.UseLife = i;
                model.CreateDate = DateTime.Now.AddDays(i);
                model.UpdateDate = DateTime.Now.AddDays(i);
                model.Creator = "admin";
                models.Add(model);
            }
            Stopwatch w = new Stopwatch();
            w.Start();
            var result = services.BatchInset(models);
            w.Stop();
            Console.WriteLine("BatchInsert ->{0},耗时：{1}毫秒", result, w.ElapsedMilliseconds);
            return models;
        }

        private void BatchUpdate()
        {
            var models = BatchInsert(2);
            models.ForEach(c => { c.RowState = System.Data.DataRowState.Modified; c.AssetsName = "BatchUpdate"; });
            for (int i = 1; i <= 1; i++)
            {
                var model = new AssetsDTO();
                model.AssetsCode = i.ToString()+ "BatchUpdate";
                model.AssetsName = i + "BatchUpdate";
                model.Id = model.NewGuid2();
                model.SN = i.ToString();
                model.UseDate = DateTime.Now.AddDays(i);
                model.UseLife = i;
                model.CreateDate = DateTime.Now.AddDays(i);
                model.UpdateDate = DateTime.Now.AddDays(i);
                model.Creator = "admin";
                models.Add(model);
            }
            Stopwatch w = new Stopwatch();
            w.Start();
            var result = services.BatchUpdate(models);
            w.Stop();
            Console.WriteLine("BatchUpdate ->{0},耗时：{1}毫秒", result, w.ElapsedMilliseconds);
        }
    }
}
